App.controller("guiderManagementCtrl",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	
	$scope.search = {};		//搜索参数
	$scope.form1 = {};		//导购
	$scope.form = {};       //设置任务
	$scope.form2 = {};    //人员批量处理的数据
	$scope.shopName_show = true;	//商户名称（显示）


	$scope.shopName_hidden = false;		//商户（隐藏）
	$scope.shopBelong_show = true;		//所属店铺（显示）
	$scope.info_show = true;	

	$scope.shopNames = true;   //所属商户搜索框
	$scope.department = true;  //部门编号
	
	$scope.addVillages_show = false;//导入小区列表按钮
	var limitParam = {format:"xls"};		//文件限制
	
	var alertModel = {};	//alert模态框
	var resultData = [];    //所属导购的数据
	var checkArr = [];    //批量处理任务
	var userNames = '';    //username 的
	var cityCode1 = null;    //商户区域的市
	var flag1 = null;         //时间的开关
	var falgNUms = false;    
	
	if(userInfo.user_level==0){	//开发者
		$scope.addGuider_show = false;
		$scope.setTask_show = false;
		$scope.organization = true;  //组织编号
	}else if(userInfo.user_level==3){	//三级用户
		$scope.setTask_show = false;
		$scope.organization = true;  //组织编号
		$scope.gitTypes = true; 
		$scope.addVillages_show = true
	}else if(userInfo.user_level==2){	//二级用户
		
		$scope.gitTypes = true;
	}else if(userInfo.user_level==1){	//一级用户
		$scope.department = false;  //部门编号
		$scope.setTask_show = false;
		$scope.shopName_show = false;
		$scope.shopName_hidden = true;   //所属商户列表的隐藏
		$scope.shopNames = false;   //所属商户搜索框
		$scope.shopBelong_show = false;
		
		$scope.gitTypes = false;
	}
	
	
	
	//表格对象
	$scope.gridOptions = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/selectBiotopeInfoPage",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var sort = [{dir:"desc",field:"create_time"}];
							if(options.sort!=null && options.sort.length>0 ){
								if(options.sort[0].field=="create_time"){
									options.sort[0].field="create_time";
								}else{
									options.sort[0].field="create_time";
								}
								
								sort=options.sort;
							}
							
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									filialeName:$scope.search.filialeName,  //创建者
									shopName:$scope.search.shopName, //专卖店
									city:$scope.search.city, //城市
									houseName:$scope.search.houseName, //小区名称
									sellerName:$scope.search.sellerName, //导购
									getRoomTime:$('#getRoomTime').val(),//收房时间(始)
									getRoomTime1:$('#getRoomTime1').val(),//收房时间(止)
									optTime:$('#optTime').val(),//扫楼时间(始)
									optTime1:$('#optTime1').val(),//扫楼时间(止)
									sort:sort
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "single"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "houseName",         
						title : "楼盘名称",     
						width : "100px"
					},
					{
						field : "filialeName",         
						title : "分公司",     
						width : "100px",
						hidden: $scope.shopName_hidden
					},
					{
						field : "shopName",         
						title : "专卖店",     
						width : "100px",
						template:function(e){
							if(e.shopName==null){
								return '无';
							}else{
								 return	e.shopName;
							}
							
						}
					},
					{
						field : "city",         
						title : "城市",     
						width : "100px"
					},
					{
						field : "area",         
						title : "地区",     
						width : "100px"
					},
					{
						field : "businessArea",         
						title : "商圈",     
						width : "100px"
					},

					{
						field : "houseType",         
						title : "楼盘类型",     
						width : "100px"
					},
					{
						field : "address",         
						title : "地址",     
						width : "100px"
					},
					{
						field : "sellerName",         
						title : "导购",     
						width : "100px",
						template:function(e){
							var template_html ='';
							if(e.sellerName==null){
								template_html = '<div class="operation k-state-default splitButtonTwoc" ng-click="updateSeller(\''+e.id+'\')" >无</div>'
							}else{
								template_html = '<div class="operation k-state-default splitButtonTwoc" ng-click="updateSeller(\''+e.id+'\')">'+e.sellerName+'</div>'
							}
							return template_html;
						}
					},
					{
						field : "getRoomTime",         
						title : "收房时间",     
						width : "100px",
						template:function(e){
							if(e.getRoomTime==null){
								return '暂无数据';
							}else{
								 return	e.getRoomTime;
							}
							
						}
					},
					{
						field : "updateTime",         
						title : "数据更新时间",     
						width : "100px",
						template:function(e){
							if(e.updateTime==null){
								return '暂未修改';
							}else{
								 return	e.updateTime;
							}
							
						}
					},
					{
						field : "optTime",         
						title : "扫楼时间",     
						width : "100px",
						template:function(e){
							if(e.optTime==null){
								return '暂无';
							}else{
								 return	 e.optTime ;
							}
							
						}
					},
					{
						field : "remark",         
						title : "备注型",     
						width : "100px",
						template:function(e){
							if(e.remark==null){
								return '无';
							}else{
								 return	e.remark;
							}
							
						}
//						values: [
//						         { text: "推广", value: 1 },
//						         { text: "店员", value: 2 },
//						         { text: "临促", value: 3 },
//						         { text: "小区推广", value: 4 }
//				        ]
					},
					{
						field : "",         
						title : "操作",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	var str = JSON.stringify(e);
					    	if(userInfo.user_level == 3){
					    		
						    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
						    										+ '<div class="operation k-state-default splitButtonTwoc" ng-click="deleteDetails(\''+e.id+'\')">删除</div>';
						    	return template_html;

					    	}else if(userInfo.user_level == 2){
						    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
						    										+ '<div class="operation k-state-default splitButtonTwoc" ng-click="deleteDetails(\''+e.id+'\')">删除</div>';
						    	return template_html;
					    	}else if(userInfo.user_level == 1){
					    		
					    	}else if(userInfo.user_level == 0){
					    		var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
					    										+ '<div class="operation k-state-default splitButtonTwoc" ng-click="deleteDetails(\''+e.id+'\')">删除</div>';
						    	return template_html;
				    		}

					    	if(userInfo.user_type==1){  //开发者
					    		
					    	}else if(userInfo.user_type==2){  //企业
					    		
					    	}else if(userInfo.user_type==3){  //合伙人
					    		
					    	}else if(userInfo.user_type==4){  //品牌
					    		
					    	}else if(userInfo.user_type==5){  //店铺
					    		
					    	}

					    	return html;
					    },
					}
			]
	};
	
	
//	//编辑(或者查看 0 是编辑 1是查看)
	$scope.editDetails = function(id,type){
		$scope.info_show = true;
		$scope.updateInfo(id);
	};
	$scope.updateInfo = function(id){
		$scope.clearDetails();
		if(userInfo.user_level== 3){
			$scope.filiale_show = true;
		}else if(userInfo.user_level== 2){
			$scope.filiale_show = false;
		}else if(userInfo.user_level== 1){
			$scope.filiale_show = false;
			$scope.shopBelong_show = false;
		}else{
			$scope.filiale_show = true;
		}
		
		
		$http({
			   url: path+'/server/selectBiotopeInfoById/'+id,
			   method: 'GET' 
		}).success(function(data){ 
			if(data.code==0){  //成功
				var resultData = data.result;
					$scope.form1.id = resultData.id;
					$scope.form1.filialeName = resultData.filialeName;
					$scope.form1.shopName = resultData.shopName;
					$scope.form1.city = resultData.city;
					$scope.form1.area = resultData.area;
					$scope.form1.businessArea = resultData.businessArea;
					$scope.form1.houseType = resultData.houseType;
					$scope.form1.houseName = resultData.houseName;
					$scope.form1.address = resultData.address;
					$scope.form1.optTime = resultData.optTime;
					$scope.form1.getRoomTime = resultData.getRoomTime;
					$scope.form1.remark = resultData.remark;
					if(resultData.filialeId){
						var filialeData = {};
						var filialeDa = [];
						filialeData.id= resultData.filialeId;
						filialeData.name= resultData.filialeName;
						filialeDa.push(filialeData);
						$("#filiale1").data("kendoDropDownList").setDataSource(filialeDa);  //所属分公司
						$("#filiale1").data("kendoDropDownList").value(resultData.filialeId);   //所属店铺
						var shopData = {};
						var shopDa = [];
						var shopData1 =  {};
						shopData1.id= "0";
						shopData1.name= "无";
						shopDa.push(shopData1);
						if(resultData.shopId){
							shopData.id= resultData.shopId;
							shopData.name= resultData.shopName;
							shopDa.push(shopData);
						}
						$http({
							url:path+"/server/getShopByfilialeId/"+resultData.filialeId ,
							method: 'GET'
						}).success(function(data){
							if(data.code ==0){
								var shops =  data.result;
								$.each(shops, function(index, OneObj){
									if(resultData.shopId){
										if(resultData.shopId != OneObj.id ){
											shopDa.push(OneObj);
										}
									}else{
										shopDa.push(OneObj);
									}
								});
								$("#belongStore").data("kendoDropDownList").setDataSource(shopDa);  //所属分公司
								if(resultData.shopId){
									$("#belongStore").data("kendoDropDownList").value(resultData.shopId);   //所属店铺
								}
							}else{
								alert(data.message)
							}
						}).error(function(data){
							console.log(data);   
						})
						
						var sellerData = {};
						var sellerDa = [];
						var sellerId = resultData.sellerId;
						var sellerData1 = {};
						sellerData1.id= "0";
						sellerData1.name= "无";
						sellerDa.push(sellerData1);
						if(resultData.sellerId){
							sellerData.id= resultData.sellerId;
							sellerData.name= resultData.sellerName;
							sellerDa.push(sellerData);
						}
						if(resultData.shopId){
							$http({
								url:path+"/server/getSellerByShopId/"+resultData.shopId ,
								method: 'GET'
							}).success(function(data){
								if(data.code ==0){
									var sellers =  data.result;
									$.each(sellers, function(index, OneObj){
										if(resultData.sellerId){
											if(resultData.sellerId !=OneObj.id ){
												sellerDa.push(OneObj);
											}
										}else{
											sellerDa.push(OneObj);
										}
										
									});
									$("#seller").data("kendoDropDownList").setDataSource(sellerDa);  //所属分公司
									if(resultData.sellerId){
										$("#seller").data("kendoDropDownList").value(resultData.sellerId);   //所属店铺
									}
								}else{
									alert(data.message)
								}
							}).error(function(data){
								console.log(data);   
							})
						}
						
					}
				$scope.BiotopeInfoWindow.center().open();
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
		
		
	};
	
	
	
	//查询
	$scope.search = function(){
		$scope.grid.dataSource.page(1);
	};
	
	
	//初始化省
	$scope.initProvince = function(){
		$("#province").kendoComboBox({
			dataTextField: "name",
			dataValueField: "code",
			placeholder: "省",
			filter: "contains",
			dataSource: {
				serverFiltering: true,
				transport: {
					read: {
						type : 'GET',
						url: path+"/server/province",
						dataType : "json"
					}
				},
				schema : {
					data : function(d) {
						return d.result;
					}
				},
			},
			change: function(e) {
				var valueList = this.value();
				provinceCode = valueList;
				if(valueList&&valueList.length>0){
					$("#area").data("kendoComboBox").value("");
				}
				$scope.getCityData(valueList);
			}
		});
	}
	
	//获取市数据
	$scope.getCityData = function(provinceCode,defaultVal){
		$http({
			url: path+"/server/city/"+provinceCode,
			method: 'GET'
		}).success(function(data){
			$scope.initCity(data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	$scope.initCity = function(cityData,defaultVal){
		if(cityData){
			var plugObj = $("#city").data("kendoComboBox");
			plugObj.value("");
			plugObj.setDataSource(cityData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#city").kendoComboBox({
				dataTextField: "name",
				dataValueField: "code",
				placeholder: "市",
				filter: "contains",
				dataSource: [],
				change: function(e) {
					var value = this.value();
					cityCode = value;
					if(value&&value.length>0){
						$("#area").data("kendoComboBox").value("");
					}
					$scope.getAreaData(value);
				}
			});
		}
	}
	
	//获取区数据
	$scope.getAreaData = function(cityCode,defaultVal){
		$http({
			url: path+"/server/county/"+cityCode,
			method: 'GET'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
		}).success(function(data){
			areaArr = data.result;
			allAreaStr = '';
			$.each(areaArr, function(index, OneObj){
				allAreaStr += (OneObj.code+",");
			});
			if(areaArr.length == 0){  //没有区的时候传市的编码
				allAreaStr = cityCode;
			}
			var allArea = {code:"all",name:"全城"};  //全城
			areaArr.unshift(allArea);
			
			$scope.initArea(areaArr,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化区
	$scope.initArea = function(areaData,defaultVal){
		if(areaData){
			var plugObj = $("#area").data("kendoComboBox");
			plugObj.setDataSource(areaData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#area").kendoComboBox({
				dataTextField: "name",
				dataValueField: "code",
				placeholder: "请选择区域",
				filter: "contains",
				dataSource: [],
				change:function(e){
					valueList = this.value();
					$scope.getCommercialInfo(provinceCode,cityCode,valueList);
				}
			});
		}
	};	

	
	//初始化省
	$scope.initProvince2 = function(){
		$("#province2").kendoComboBox({
			dataTextField: "name",
			dataValueField: "code",
			placeholder: "省",
			filter: "contains",
			dataSource: {
				serverFiltering: true,
				transport: {
					read: {
						type : 'GET',
						url: path+"/server/province",
						dataType : "json"
					}
				},
				schema : {
					data : function(d) {
						return d.result;
					}
				},
			},
			change: function(e) {
				var valueList = this.value();
				provinceCode2 = valueList;
				if(valueList&&valueList.length>0){
					$("#area2").data("kendoComboBox").value("");
					$scope.clearShop();
				}
				$scope.getCityData2(valueList);
			}
		});
	}
	
	//获取市数据
	$scope.getCityData2 = function(provinceCode,defaultVal){
		$http({
			url: path+"/server/city/"+provinceCode,
			method: 'GET'
		}).success(function(data){
			$scope.initCity2(data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	$scope.initCity2 = function(cityData,defaultVal){
		if(cityData){
			var plugObj = $("#city2").data("kendoComboBox");
			plugObj.value("");
			plugObj.setDataSource(cityData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#city2").kendoComboBox({
				dataTextField: "name",
				dataValueField: "code",
				placeholder: "市",
				filter: "contains",
				dataSource: [],
				change: function(e) {
					var value = this.value();
					cityCode2 = value;
					if(value&&value.length>0){
						$("#area2").data("kendoComboBox").value("");
						$scope.clearShop();
					}
					$scope.getAreaData2(value);
				}
			});
		}
	}
	
	//获取区数据
	$scope.getAreaData2 = function(cityCode,defaultVal){
		$http({
			url: path+"/server/county/"+cityCode,
			method: 'GET'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
		}).success(function(data){
			areaArr = data.result;
			allAreaStr = '';
			$.each(areaArr, function(index, OneObj){
				allAreaStr += (OneObj.code+",");
			});
			if(areaArr.length == 0){  //没有区的时候传市的编码
				allAreaStr = cityCode;
			}
			var allArea = {code:"all",name:"全城"};  //全城
			areaArr.unshift(allArea);
			
			$scope.initArea2(areaArr,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化区
	$scope.initArea2 = function(areaData,defaultVal){
		if(areaData){
			var plugObj = $("#area2").data("kendoComboBox");
			plugObj.setDataSource(areaData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#area2").kendoComboBox({
				dataTextField: "name",
				dataValueField: "code",
				placeholder: "请选择区域",
				filter: "contains",
				dataSource: [],
				change:function(e){
					valueList = this.value();
					$scope.getCommercialInfo1(provinceCode2,cityCode2,valueList);
					$scope.clearShop();
				}
			});
		}
	};	
	
	

	
	//获取店铺列表
	$scope.getShopList = function(code){
		if(code == 'all'){
			code = cityCode1;
		}
		var paramObj = {
				code:code
		};
		
		$http({
			   url: path+'/server/selectStairShopsByUid',
			   method: 'POST',
			   data: angular.toJson(paramObj), 
		}).success(function(data){ 
			if(data.code==0){  //成功
				if(data.result || data.result.length>0){
					var dataArr = [];
					$.each(data.result,function(index,objs){
						var results = {}
					results.id = index.split('_')[1];
					results.name= objs;
					dataArr.push(results);
					});
					$("#belongStore").data("kendoDropDownList").setDataSource(dataArr);
				}
				
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
	};
	
	//提示信息
	$scope.alertMessage = function(message){
		alertModel.pannel = jqueryAlert({
			content: message,
			modal: true
		});
	}
	
	//全选，取消
	$scope.chooseAll = function(className,flag){
		publicService.chooseAllByClassName(className,flag);
	}
	
	//导出表格数据（1：筛选导出，2：选中导出）  
	$scope.downloadTableData = function(type){
		var paramObj = {};
		
		if(type==1){	//筛选导出
			paramObj = {
					page : 1, 
					pageSize : 10,
					ispage:false,
					param:{
						filialeName:$scope.search.filialeName,  //创建者
						shopName:$scope.search.shopName, //专卖店
						city:$scope.search.city, //城市
						houseName:$scope.search.houseName, //小区名称
						sellerName:$scope.search.sellerName, //导购
						getRoomTime:$('#getRoomTime').val(),//收房时间(始)
						getRoomTime1:$('#getRoomTime1').val(),//收房时间(止)
						optTime:$('#optTime').val(),//扫楼时间(始)
						optTime1:$('#optTime1').val(),//扫楼时间(止)
					}
			};
		}else if(type==2){	//选中导出
			var ids = publicService.getChooseValueByClassName("recordClass");
			if(ids.length==0){
				$scope.alertMessage("请选择数据！");
				return;
			}
			
			paramObj = {
					page : 1, 
					pageSize : 10,
					param:{
						ids: ids
					}
			};
		}

		var requestUrl = path+"/server/export";		//请求路径
		var exportModule = "biotopeInfo_model";	//模块名称
		var form = $("<form method='POST' action='"+requestUrl+"' target='_self'>"
						+"<input type='hidden' name='module_code' value='"+exportModule+"'/>"
						+"<input type='hidden' name='page' value='"+angular.toJson(paramObj)+"'/>"
					+"</form>");
		console.log("【表单参数】",form.serializeArray());
	    $(document.body).append(form);
	    form.submit();	
	}
	


	
	//-----------------panminghua -------
	//选中的分公司展示实例化
	$scope.showJoinComp = function(contains,name,Id){
		$("#"+contains).kendoDropDownList({
		    placeholder: "暂未有礼品选中",
		    dataSource: [],
			dataTextField:name,
		    dataValueField:Id,
	      	change: function(e) {
	      	},
		});
	};
	
	//参与商户的初始化（选择）
	$scope.selecttComercial = function(){
		$("#userShop").kendoDropDownList({
		    dataTextField: "name",
		    dataValueField: "id",
		    placeholder:"请选择商户",
		    dataSource: [],
		    change: function(e) {
		    	var chooseObj = this.dataItem();
		    	var chooseValue = chooseObj.id;
	      	},
		});
	};
	//参与店铺的初始化（选择）
	$scope.selectShop = function(){
		$("#belongStore").kendoDropDownList({
			dataTextField: "name",
			dataValueField: "id",
			placeholder:"请选择商户",
			dataSource: [],
			change: function(e) {
				var chooseObj = this.dataItem();
				var chooseValue = chooseObj.id;
				$scope.getSellerByShopId(chooseValue);
			},
		});
	};
	$scope.selectSeller = function(){
		$("#seller").kendoDropDownList({
			dataTextField: "name",
			dataValueField: "id",
			placeholder:"请选择导购",
			dataSource: [],
			change: function(e) {
				var chooseObj = this.dataItem();
				var chooseValue = chooseObj.id;
			},
		});
	};
	//参与商户的初始化（选择）
	$scope.selecttComercial1 = function(){
		$("#filiale1").kendoDropDownList({
		    dataTextField: "name",
		    dataValueField: "id",
		    placeholder:"请选择商户",
		    dataSource: [],
		    change: function(e) {
		    	var chooseObj = this.dataItem();
		    	var chooseValue = chooseObj.id;
		    	$scope.getShopByfilialeId(chooseValue);
	      	},
		});
	};
	//获取店铺信息
	$scope.getShopByfilialeId = function(id){
		$http({
			   url:path+"/server/getShopByfilialeId/"+id ,
			   method: 'GET',
		}).success(function(data){
			var dataList = [];
			var values = []; 
			var data1 = {"id":"0","name":"无"};
			dataList.push(data1);
			values.push(0);
			$.each(data.result,function(index,oneObj){
					var dataObj = {
							name: oneObj.name,
							id: oneObj.id
					};
				
				dataList.push(dataObj);
				values.push(dataObj.id);
			});
			
			$("#belongStore").data("kendoDropDownList").setDataSource(dataList);

		}).error(function(data){
			console.log(data);   
		})
	};
	//获取导购信息
	$scope.getSellerByShopId = function(id){
		$http({
			url:path+"/server/getSellerByShopId/"+id ,
			method: 'GET',
		}).success(function(data){
			var dataList = [];
			var values = []; 
			var data1 = {"id":"0","name":"无"};
			dataList.push(data1);
			values.push(0);
			$.each(data.result,function(index,oneObj){
				var dataObj = {
						name: oneObj.name,
						id: oneObj.id
				};
				
				dataList.push(dataObj);
				values.push(dataObj.id);
			});
			
			$("#seller").data("kendoDropDownList").setDataSource(dataList);
			
		}).error(function(data){
			console.log(data);   
		})
	};
	
	 //获取分公司或店铺的信息
	$scope.getCommercialInfo = function(pcode,ccode,acode){
		var baseOrder = {
				region_code: acode=="all"?ccode:acode
		};
		var urls = "";
		if(userInfo.user_level == 3){  //集团
			urls =  path+"/server/selectFilialeByCode";
		}if(userInfo.user_level == 2){  //分公司
			urls = path+"/server/selectShopByCode";
		}
		$http({
			   url:urls ,
			   method: 'POST',
			   data:baseOrder
		}).success(function(data){
			var dataList = [];
			var values = []; 
			$.each(data.result,function(index,oneObj){
				if(userInfo.user_level == 3){ //集团
					var dataObj = {
							name: oneObj.filialeName,
							id: oneObj.filialeId
					};
				}else if(userInfo.user_level == 2){//分公司
					var dataObj = {
							name: oneObj.shopName,
							id: oneObj.shopId
					};
				}
				dataList.push(dataObj);
				values.push(dataObj.id);
			});
			
			$("#userShop").data("kendoDropDownList").setDataSource(dataList);

		}).error(function(data){
			console.log(data);   
		})
	};
	//获取分公司或店铺的信息
	$scope.getCommercialInfo1 = function(pcode,ccode,acode){
		var baseOrder = {
				region_code: acode=="all"?ccode:acode
		};
		var urls = "";
		if(userInfo.user_level == 3){  //集团
			urls =  path+"/server/selectFilialeByCode";
		}if(userInfo.user_level == 2){  //分公司
			urls = path+"/server/selectShopByCode";
		}
		$http({
			url:urls ,
			method: 'POST',
			data:baseOrder
		}).success(function(data){
			var dataList = [];
			var values = []; 
			if(data.result && data.result.length>0){
				$.each(data.result,function(index,oneObj){
					if(userInfo.user_level == 3){ //集团
						var dataObj = {
								name: oneObj.filialeName,
								id: oneObj.filialeId
						};
					}else if(userInfo.user_level == 2){//分公司
						var dataObj = {
								name: oneObj.shopName,
								id: oneObj.shopId
						};
					}
					dataList.push(dataObj);
					values.push(dataObj.id);
				});
				
				$("#filiale1").data("kendoDropDownList").setDataSource(dataList);
				
			}
			
		}).error(function(data){
			console.log(data);   
		})
	};
	
	
	
	//设置任务
	$scope.setTask = function(){
		$location.path("/setTask");
	}
	
	//添加小区列表
	$scope.addVillages = function(){
		$scope.villageWindow.center().open();
	}

	
	publicService.initDate("getRoomTime");	//创建时间（始）
	publicService.initDate("getRoomTime1");	//创建时间（止）
	publicService.initDate("optTime");		//扫楼时间（止）
	publicService.initDate("optTime1");		//扫楼时间（止）
	
	
	$scope.initProvince();			//初始化省（参与商户）
	$scope.initCity();				//初始化市（参与商户）
	$scope.initArea();				//初始化区（参与商户）
	$scope.initProvince2();			//初始化省（参与商户）
	$scope.initCity2();				//初始化市（参与商户）
	$scope.initArea2();				//初始化区（参与商户）
	
	publicService.initTaskType("taskType");			//初始化【任务类型】
	
	

	
	$scope.selecttComercial();	//初始化用户【展示】
	$scope.selecttComercial1();	//初始化用户【展示】
	$scope.selectShop();
	$scope.selectSeller();
	//添加小区列表
	$scope.addGuiderToServer = function(){
		var formData = new FormData();
		
		var filialeId = $('#userShop').val();
		if(!filialeId){
			alert("请选择分公司！");
			return;
		}
		
		formData.append("filialeId", filialeId);
		
		var file = $('#excelFile')[0].files[0]
		if(!file){
			alert("请选择文件！");
			return;
		}
		formData.append("file", file);
		$.ajax({
			   url: path+"/server/addBiotopeInfoByExcel" ,
			   method: 'POST',
			   data:formData,
			   cache: false,
		         processData: false,
		         contentType: false,
		         async: false
		}).success(function(data){
			$scope.villageWindow.center().close();
			alert("导入数据成功");
			$scope.grid.dataSource.page(1);
		}).error(function(data){
			console.log(data);   
		})
	}
	$scope.updateBiotopeInfo = function(){
		
		var biotopeInfo ={};
		biotopeInfo.id = $scope.form1.id;
		biotopeInfo.filialeName = $scope.form1.filialeName;
		biotopeInfo.city = $scope.form1.city;
		biotopeInfo.area = $scope.form1.area;
		biotopeInfo.businessArea = $scope.form1.businessArea;
		biotopeInfo.houseType = $scope.form1.houseType;
		biotopeInfo.houseName = $scope.form1.houseName;
		biotopeInfo.address = $scope.form1.address;
		biotopeInfo.optTime = $scope.form1.optTime;
		biotopeInfo.remark = $scope.form1.remark;
		biotopeInfo.getRoomTime = $scope.form1.getRoomTime;
		biotopeInfo.sellerId = $("#seller").val();
		biotopeInfo.shopId = $("#belongStore").val();
		biotopeInfo.filialeId = $("#filiale1").val();
		
		$http({
			url:path+"/server/updateBiotopeInfo" ,
			method: 'POST',
			data:biotopeInfo
		}).success(function(data){
			if(data.code ==0){
				alert("修改成功")
				$scope.BiotopeInfoWindow.center().close();
				$scope.grid.dataSource.page(1);
			}else{
				alert(data.message)
			}
			
		}).error(function(data){
			console.log(data);   
		})
		
		
	}
	
	
	$scope.deleteDetails = function (id){
		
		$http({
			url:path+"/server/deleteBiotopeInfoById/"+id ,
			method: 'GET'
		}).success(function(data){
			if(data.code ==0){
				alert("删除成功")
				$scope.grid.dataSource.page(1);
			}else{
				alert(data.message)
			}
		}).error(function(data){
			console.log(data);   
		})
	}
	
	$scope.clearDetails = function (){
		$("#filiale1").data("kendoDropDownList").setDataSource();  //所属分公司
		$("#filiale1").data("kendoDropDownList").value();  
		$("#belongStore").data("kendoDropDownList").setDataSource();  
		$("#belongStore").data("kendoDropDownList").value();   
		$("#seller").data("kendoDropDownList").setDataSource(); 
		$("#seller").data("kendoDropDownList").value();  
		$scope.form1.id = "";
		$scope.form1.filialeName = "";
		$scope.form1.shopName = "";
		$scope.form1.city = "";
		$scope.form1.area = "";
		$scope.form1.businessArea = "";
		$scope.form1.houseType = "";
		$scope.form1.houseName = "";
		$scope.form1.address = "";
		$scope.form1.optTime = "";
		$scope.form1.getRoomTime = "";
		$scope.form1.remark = "";
	}
	
	$scope.clearShop = function (){
		$("#filiale1").data("kendoDropDownList").setDataSource();  //所属分公司
		$("#filiale1").data("kendoDropDownList").value();  
		$("#belongStore").data("kendoDropDownList").setDataSource();  
		$("#belongStore").data("kendoDropDownList").value();   
		$("#seller").data("kendoDropDownList").setDataSource(); 
		$("#seller").data("kendoDropDownList").value();  
	}
	$scope.updateSeller = function (id){
		$scope.info_show = false;
		$scope.updateInfo(id);
	}
	
});